django model.ForeignKey.on_delete
- description
- No value
- aliases
- No value
- tags
- No value
- created
- 2023-06-02T11:25:11
- updated
- 2023-07-15T21:30:20
- title
- django model.ForeignKey.on_delete
https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.ForeignKey.on_delete
The possible values for on_delete are found in django.db.models:
-
CASCADE¶Cascade deletes. Django emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey.
Model.delete()isn’t called on related models, but thepre_deleteandpost_deletesignals are sent for all deleted objects. -
PROTECT¶Prevent deletion of the referenced object by raising
ProtectedError, a subclass ofdjango.db.IntegrityError. -
RESTRICT¶Prevent deletion of the referenced object by raising
RestrictedError(a subclass ofdjango.db.IntegrityError). UnlikePROTECT, deletion of the referenced object is allowed if it also references a different object that is being deleted in the same operation, but via aCASCADErelationship.